

import time


class Role():
    # 接受名字，性别，血量，攻击力量，防弹衣血量，技能名参数
    def __init__(self, name, gender, blood, power, armor, skill) -> None:
        self.name = name
        self.gender = gender
        self.blood = blood
        self.power = power
        self.armor = armor
        self.skill = skill
    # 攻击
    def attack(self, enemy):
        if enemy.blood <= 0 or self.blood<=0:
            return 'stop'
        if enemy.armor > 0:
            enemy.armor -= self.power - 5
            enemy.blood -= 5
        else:
            enemy.blood -= self.power
        return 'continue'
                
                
                
class Room():
    def __init__(self) -> None:
        self.status = 'start'
    def append_role(self, role1:Role, role2:Role):
        # 加入2个玩家并初定攻击方与防御方
        self.attacker = role1
        self.defender = role2
    # 战斗函数
    def battle(self):
        if self.attacker.blood > 0 and self.defender.blood > 0:
            self.attacker.attack(self.defender)
            # 如果防御方血量小于等于0数目，赢家为当前攻击方，战斗结束
            if self.defender.blood <= 0:
                self.status = 'stop'
                self.winer = self.attacker
            # 攻击方与防御方身份互换
            self.attacker, self.defender = self.defender, self.attacker


# 定义角色与玩家选择角色
roles = [
    ('嘎子', '男', 100, 10, 50, '无敌神狙'),
    ('哮天犬', '公', 100, 12, 40, '口下不留情'),
    ('刘华强', '男', 100, 11, 48, '西瓜吹水'),
    ('黎卓富', '男', 100, 14, 38, '音波功')
]
def play_roles(roles):
    for i, role in enumerate(roles):
        print(f'{i+1} 角色名: {role[0]}  性别: {role[1]}  血量: {role[2]}  攻击力: {role[3]}  防御力: {role[4]} 技能: {role[5]}')
        
print('1号玩家选择你的角色')
play_roles(roles)
while True:
    role1_id = input('输入角色编号: ')
    if not role1_id or not role1_id.isdigit() or int(role1_id) > len(roles):
        print('没有此角色，请重新输入！')
    else:
        role1_id = int(role1_id)
        role1 = Role(*roles[role1_id-1])
        print(f'你选择的角色为{roles[role1_id-1][0]}')
        break

tmp_roles = roles[:role1_id-1]+roles[role1_id:]
print('2号玩家选择你的角色')
play_roles(tmp_roles)
while True:
    role2_id = input('输入角色编号: ')
    if not role2_id or not role2_id.isdigit() or int(role2_id) > len(tmp_roles):
        print('没有此角色，请重新输入！')
    else:
        role2_id = int(role2_id)
        role2 = Role(*tmp_roles[role2_id-1])
        print(f'你选择的角色为{tmp_roles[role2_id-1][0]}')
        break

vipRoom = Room()
vipRoom.append_role(role1, role2)



print('游戏开始...')
while True:
    if vipRoom.status != 'stop':
        vipRoom.battle()
        attacker = vipRoom.defender
        defender = vipRoom.attacker
        print(f'{attacker.name}对{defender.name}施展了{attacker.skill}技能，{defender.name}剩余血量{defender.blood}')
    else:
        print(f'战斗结束,{vipRoom.winer.name}赢了！')
        break
    time.sleep(0.5)